package logic

import (
	"context"
	"zero_demo06_rpc_api/user/api/internal/svc"
	"zero_demo06_rpc_api/user/api/internal/types"
	"zero_demo06_rpc_api/user/rpc/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserInfoLogic) UserInfo(req *types.UserInfoRequest) (resp *types.UserInfoResponse, err error) {
	// todo: add your logic here and delete this line
	userInfo, err := l.svcCtx.UserRpc.UserInfoById(l.ctx, &user.UserInfoRequest{UserId: req.Id})
	if err != nil {
		return &types.UserInfoResponse{}, err
	}
	return &types.UserInfoResponse{
		Id:       userInfo.UserId,
		Username: userInfo.Username,
	}, nil
}
